package com.darrenchan

object ForDemo2 {
  def main(args: Array[String]): Unit = {
    //循环有三个东西，分别是to, until, Range
    //1 to 10 <==> 1.to(10) 左闭右闭
    //1 until 10 <==> 1.until(10) 左闭右开
    //Range(1, 10, 1)第三个参数是step 左闭右开
    for(x <- 1 to 10) {
      print(x + " ")
    }

    println()
    //等同于上面的写法
    (1 to 10).foreach(x => print(x + " "))

    println()
    var i = 0
    do {
      print((1 to 10)(i) + " ")
      i += 1
    }while(i < (1 to 10).length)


    println()
    i = 0
    while(i < (1 to 10).length) {
      print((1 to 10)(i) + " ")
      i += 1
    }

  }
}
